package sol.leetcode;

/**
 * Reverse Vowels of a String
 */
public class Issue345 {
    public static String reverseVowels(String s) {
        char[] str = s.toCharArray();
        for (int p = 0, q = s.length() - 1; p < q; p++, q--) {
            while (p < q && !isVowel(str[p]))
                p++;
            while (p < q && !isVowel(str[q]))
                q--;
            if (p < q) {
                char c = str[p];
                str[p] = str[q];
                str[q] = c;
            }
        }
        return new String(str);
    }

    public static boolean isVowel(char c) {
        switch (c) {
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
                return true;
            default:
                return false;
        }

    }

    public static void main(String[] args) {
        String str = "leetcode";
        System.out.println(reverseVowels(str));
    }
}
